package com.zline.foodraise.view;

import android.content.Context;
import android.support.v7.widget.CardView;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.makeramen.roundedimageview.RoundedImageView;
import com.nostra13.universalimageloader.core.DisplayImageOptions;
import com.nostra13.universalimageloader.core.ImageLoader;
import com.zline.foodraise.R;
import com.zline.foodraise.entity.ProjectBean;
import com.zline.foodraise.listener.RecyclerItemClicked;
import com.zline.foodraise.listener.RippleForegroundListener;

import org.androidannotations.annotations.Click;
import org.androidannotations.annotations.EViewGroup;
import org.androidannotations.annotations.ViewById;

/**
 * Created by heshantao on 15/7/2.
 * 筹店中众筹商品列表
 */
@EViewGroup(R.layout.raise_product_card_item)
public class RaiseProductCardItem extends RelativeLayout {
    private static final String LOG_TAG=RaiseProductCardItem.class.getSimpleName();
    RecyclerItemClicked itemClicked;
    //众筹商品名称
    @ViewById(R.id.zc_product_name_tv)
    TextView pro_name_tv;
    //众筹状态：1.审核中2筹资中3研发中4项目成功5销售中6项目失败
    @ViewById(R.id.zc_product_status_tv)
    TextView pro_status_tv;
    //当前众筹人数
    @ViewById(R.id.zc_product_order_num_value_tv)
    TextView count_tv;
    //众筹钱数
    @ViewById(R.id.zc_product_amount_value_tv)
    TextView totle_amount_tv;
    @ViewById(R.id.zc_product_icon_riv)
    RoundedImageView product_riv;
    @ViewById(R.id.zc_list_item_cv)
    CardView cardView;
    int position;
    @ViewById(R.id.zc_product_look_all_orders_rl)
    RelativeLayout look_all_rl;


    public RaiseProductCardItem(Context context) {
        super(context);
    }

    public void bind(ProjectBean projectBean,int position,DisplayImageOptions options) {
        this.position=position;
        pro_name_tv.setText(projectBean.getProjectName());
        String count=projectBean.getCurrentCount()+"";
        count_tv.setText(count);
        totle_amount_tv.setText("￥"+projectBean.getCurrentAmount());
        int status=projectBean.getStatus();
        ImageLoader imageLoader=ImageLoader.getInstance();
        imageLoader.displayImage(projectBean.getDetailPicUrl(),product_riv,options);
        RippleForegroundListener listener = new RippleForegroundListener();
        listener.setView(cardView);
        look_all_rl.setOnTouchListener(listener);
        switch (status){
            case 1:
                pro_status_tv.setText(R.string.checking);
                break;
            case 2:
                pro_status_tv.setText(R.string.raising);
                break;
            case 3:
                pro_status_tv.setText(R.string.developing);
                break;
            case 4:
                pro_status_tv.setText(R.string.raised);
                break;
            case 5:
                pro_status_tv.setText(R.string.saling);
                break;
            case 6:
                pro_status_tv.setText(R.string.failed);
                break;
            default:
                break;
        }

    }

    @Click({R.id.zc_product_look_all_orders_rl})
    void onClick(View view) {
        switch (view.getId()){
            case R.id.zc_product_look_all_orders_rl:
                itemClicked.onRecyclerItemClicked(position);
            break;
            default:
                break;
        }
    }


    public void setRecycleItemListener(RecyclerItemClicked recycleItemListener) {
        this.itemClicked = recycleItemListener;
    }
}
